home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / amiutils / i_l / irit5 / cagd_lib / cagd2gen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-31  |  59.0 KB  |  1,265 lines

  1. /******************************************************************************
  2. * Cagd_gen.c - General routines used by all modules of CAGD_lib.          *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Mar. 90.                          *
  5. ******************************************************************************/
  6.  
  7. #include <string.h>
  8. #include "cagd_loc.h"
  9. #include "geomat3d.h"
  10. #include "miscattr.h"
  11.  
  12. /* Control of the linear order surface convertion to polygon: */
  13. CagdLin2PolyType
  14.     _CagdLin2Poly = CAGD_ONE_POLY_PER_COLIN;
  15.  
  16. /*****************************************************************************
  17. * DESCRIPTION:                                                               M
  18. * Allocates and copies a list of vector structures.                     M
  19. *                                                                            *
  20. * PARAMETERS:                                                                M
  21. *   VecList:       To be copied.                                             M
  22. *                                                                            *
  23. * RETURN VALUE:                                                              M
  24. *   CagdVecStruct *:  A duplicated list of vectors.                          M
  25. *                                                                            *
  26. * KEYWORDS:                                                                  M
  27. *   CagdVecCopyList, copy                                                    M
  28. *****************************************************************************/
  29. CagdVecStruct *CagdVecCopyList(CagdVecStruct *VecList)
  30. {
  31.     CagdVecStruct *VecTemp, *NewVecList;
  32.  
  33.     if (VecList == NULL)
  34.     return NULL;
  35.     VecTemp = NewVecList = CagdVecCopy(VecList);
  36.     VecList = VecList -> Pnext;
  37.     while (VecList) {
  38.     VecTemp -> Pnext = CagdVecCopy(VecList);
  39.     VecTemp = VecTemp -> Pnext;
  40.     VecList = VecList -> Pnext;
  41.     }
  42.     return NewVecList;
  43. }
  44.  
  45. /*****************************************************************************
  46. * DESCRIPTION:                                                               M
  47. * Allocates and copies a list of plane structures.                     M
  48. *                                                                            *
  49. * PARAMETERS:                                                                M
  50. *   PlaneList:       To be copied.                                           M
  51. *                                                                            *
  52. * RETURN VALUE:                                                              M
  53. *   CagdPlaneStruct *:  A duplicated list of planes.                         M
  54. *                                                                            *
  55. * KEYWORDS:                                                                  M
  56. *   CagdPlaneCopyList, copy                                                  M
  57. *****************************************************************************/
  58. CagdPlaneStruct *CagdPlaneCopyList(CagdPlaneStruct *PlaneList)
  59. {
  60.     CagdPlaneStruct *PlaneTemp, *NewPlaneList;
  61.  
  62.     if (PlaneList == NULL)
  63.     return NULL;
  64.     PlaneTemp = NewPlaneList = CagdPlaneCopy(PlaneList);
  65.     PlaneList = PlaneList -> Pnext;
  66.     while (PlaneList) {
  67.     PlaneTemp -> Pnext = CagdPlaneCopy(PlaneList);
  68.     PlaneTemp = PlaneTemp -> Pnext;
  69.     PlaneList = PlaneList -> Pnext;
  70.     }
  71.     return NewPlaneList;
  72. }
  73.  
  74. /*****************************************************************************
  75. * DESCRIPTION:                                                               M
  76. * Allocates and copies a list of bbox structures.                     M
  77. *                                                                            *
  78. * PARAMETERS:                                                                M
  79. *   BBoxList:       To be copied.                                            M
  80. *                                                                            *
  81. * RETURN VALUE:                                                              M
  82. *   CagdBBoxStruct *:  A duplicated list of bbox's.                          M
  83. *                                                                            *
  84. * KEYWORDS:                                                                  M
  85. *   CagdBBoxCopyList, copy                                                   M
  86. *****************************************************************************/
  87. CagdBBoxStruct *CagdBBoxCopyList(CagdBBoxStruct *BBoxList)
  88. {
  89.     CagdBBoxStruct *BBoxTemp, *NewBBoxList;
  90.  
  91.     if (BBoxList == NULL)
  92.     return NULL;
  93.     BBoxTemp = NewBBoxList = CagdBBoxCopy(BBoxList);
  94.     BBoxList = BBoxList -> Pnext;
  95.     while (BBoxList) {
  96.     BBoxTemp -> Pnext = CagdBBoxCopy(BBoxList);
  97.     BBoxTemp = BBoxTemp -> Pnext;
  98.     BBoxList = BBoxList -> Pnext;
  99.     }
  100.     return NewBBoxList;
  101. }
  102.  
  103. /*****************************************************************************
  104. * DESCRIPTION:                                                               M
  105. * Allocates and copies a list of polyline structures.                     M
  106. *                                                                            *
  107. * PARAMETERS:                                                                M
  108. *   PolyList:       To be copied.                                            M
  109. *                                                                            *
  110. * RETURN VALUE:                                                              M
  111. *   CagdPolylineStruct *:  A duplicated list of polylines.                   M
  112. *                                                                            *
  113. * KEYWORDS:                                                                  M
  114. *   CagdPolylineCopyList, copy                                               M
  115. *****************************************************************************/
  116. CagdPolylineStruct *CagdPolylineCopyList(CagdPolylineStruct *PolyList)
  117. {
  118.     CagdPolylineStruct *PolyTemp, *NewPolyList;
  119.  
  120.     if (PolyList == NULL)
  121.     return NULL;
  122.     PolyTemp = NewPolyList = CagdPolylineCopy(PolyList);
  123.     PolyList = PolyList -> Pnext;
  124.     while (PolyList) {
  125.     PolyTemp -> Pnext = CagdPolylineCopy(PolyList);
  126.     PolyTemp = PolyTemp -> Pnext;
  127.     PolyList = PolyList -> Pnext;
  128.     }
  129.     return NewPolyList;
  130. }
  131.  
  132. /*****************************************************************************
  133. * DESCRIPTION:                                                               M
  134. * Allocates and copies a list of polygon structures.                     M
  135. *                                                                            *
  136. * PARAMETERS:                                                                M
  137. *   PolyList:       To be copied.                                            M
  138. *                                                                            *
  139. * RETURN VALUE:                                                              M
  140. *   CagdPolygontruct *:  A duplicated list of polygons.                      M
  141. *                                                                            *
  142. * KEYWORDS:                                                                  M
  143. *   CagdPolygonCopyList, copy                                                M
  144. *****************************************************************************/
  145. CagdPolygonStruct *CagdPolygonCopyList(CagdPolygonStruct *PolyList)
  146. {
  147.     CagdPolygonStruct *PolyTemp, *NewPolyList;
  148.  
  149.     if (PolyList == NULL)
  150.     return NULL;
  151.     PolyTemp = NewPolyList = CagdPolygonCopy(PolyList);
  152.     PolyList = PolyList -> Pnext;
  153.     while (PolyList) {
  154.     PolyTemp -> Pnext = CagdPolygonCopy(PolyList);
  155.     PolyTemp = PolyTemp -> Pnext;
  156.     PolyList = PolyList -> Pnext;
  157.     }
  158.     return NewPolyList;
  159. }
  160.  
  161. /*****************************************************************************
  162. * DESCRIPTION:                                                               M
  163. * Deallocates and frees all slots of a curve structure.                     M
  164. *                                                                            *
  165. * PARAMETERS:                                                                M
  166. *   Crv:       To be deallocated.                                            M
  167. *                                                                            *
  168. * RETURN VALUE:                                                              M
  169. *   void                                                                     M
  170. *                                                                            *
  171. * KEYWORDS:                                                                  M
  172. *   CagdCrvFree, free                                                        M
  173. *****************************************************************************/
  174. void CagdCrvFree(CagdCrvStruct *Crv)
  175. {
  176.     int i, MaxAxis;
  177.  
  178.     if (Crv == NULL)
  179.     return;
  180.  
  181.     MaxAxis = CAGD_NUM_OF_PT_COORD(Crv -> PType);
  182.  
  183.     for (i = !CAGD_IS_RATIONAL_CRV(Crv); i <= MaxAxis; i++)
  184.     IritFree((VoidPtr) Crv -> Points[i]);
  185.  
  186.     if (Crv -> KnotVector != NULL)
  187.     IritFree((VoidPtr) Crv -> KnotVector);
  188.  
  189.     AttrFreeAttributes(&Crv -> Attr);
  190.     IritFree((VoidPtr) Crv);
  191. }
  192.  
  193. /*****************************************************************************
  194. * DESCRIPTION:                                                               M
  195. * Deallocates and frees a curve structure list:                     M
  196. *                                                                            *
  197. * PARAMETERS:                                                                M
  198. *   CrvList:  To be deallocated.                                             M
  199. *                                                                            *
  200. * RETURN VALUE:                                                              M
  201. *   void                                                                     M
  202. *                                                                            *
  203. * KEYWORDS:                                                                  M
  204. *   CagdCrvFreeList, free                                                    M
  205. *****************************************************************************/
  206. void CagdCrvFreeList(CagdCrvStruct *CrvList)
  207. {
  208.     CagdCrvStruct *CrvTemp;
  209.  
  210.     while (CrvList) {
  211.     CrvTemp = CrvList -> Pnext;
  212.     CagdCrvFree(CrvList);
  213.     CrvList = CrvTemp;
  214.     }
  215. }
  216.  
  217. /*****************************************************************************
  218. * DESCRIPTION:                                                               M
  219. * Deallocates and frees all slots of a surface sstructure.                 M
  220. *                                                                            *
  221. * PARAMETERS:                                                                M
  222. *   Srf:       To be deallocated.                                            M
  223. *                                                                            *
  224. * RETURN VALUE:                                                              M
  225. *   void                                                                     M
  226. *                                                                            *
  227. * KEYWORDS:                                                                  M
  228. *   CagdSrfFree, free                                                        M
  229. *****************************************************************************/
  230. void CagdSrfFree(CagdSrfStruct *Srf)
  231. {
  232.     int i, MaxAxis;
  233.  
  234.     if (Srf == NULL)
  235.     return;
  236.  
  237.     MaxAxis = CAGD_NUM_OF_PT_COORD(Srf -> PType);
  238.  
  239.     for (i = !CAGD_IS_RATIONAL_SRF(Srf); i <= MaxAxis; i++)
  240.     IritFree((VoidPtr) Srf -> Points[i]);
  241.  
  242.     if (Srf -> UKnotVector != NULL)
  243.     IritFree((VoidPtr) Srf -> UKnotVector);
  244.     if (Srf -> VKnotVector != NULL)
  245.     IritFree((VoidPtr) Srf -> VKnotVector);
  246.  
  247.     AttrFreeAttributes(&Srf -> Attr);
  248.     IritFree((VoidPtr) Srf);
  249. }
  250.  
  251. /*****************************************************************************
  252. * DESCRIPTION:                                                               M
  253. * Deallocates and frees a surface structure list:                 M
  254. *                                                                            *
  255. * PARAMETERS:                                                                M
  256. *   SrfList:  To be deallocated.                                             M
  257. *                                                                            *
  258. * RETURN VALUE:                                                              M
  259. *   void                                                                     M
  260. *                                                                            *
  261. * KEYWORDS:                                                                  M
  262. *   CagdSrfFreeList, free                                                    M
  263. *****************************************************************************/
  264. void CagdSrfFreeList(CagdSrfStruct *SrfList)
  265. {
  266.     CagdSrfStruct *SrfTemp;
  267.  
  268.     while (SrfList) {
  269.     SrfTemp = SrfList -> Pnext;
  270.     CagdSrfFree(SrfList);
  271.     SrfList = SrfTemp;
  272.     }
  273. }
  274.  
  275. /*****************************************************************************
  276. * DESCRIPTION:                                                               M
  277. * Deallocates and frees all slots of a UV structure.                     M
  278. *                                                                            *
  279. * PARAMETERS:                                                                M
  280. *   UV:       To be deallocated.                                             M
  281. *                                                                            *
  282. * RETURN VALUE:                                                              M
  283. *   void                                                                     M
  284. *                                                                            *
  285. * KEYWORDS:                                                                  M
  286. *   CagdUVFree, free                                                         M
  287. *****************************************************************************/
  288. void CagdUVFree(CagdUVStruct *UV)
  289. {
  290.     if (UV == NULL)
  291.     return;
  292.  
  293.     AttrFreeAttributes(&UV -> Attr);
  294.     IritFree((VoidPtr) UV);
  295. }
  296.  
  297. /*****************************************************************************
  298. * DESCRIPTION:                                                               M
  299. * Deallocates and frees a UV structure list:                     M
  300. *                                                                            *
  301. * PARAMETERS:                                                                M
  302. *   UVList:  To be deallocated.                                              M
  303. *                                                                            *
  304. * RETURN VALUE:                                                              M
  305. *   void                                                                     M
  306. *                                                                            *
  307. * KEYWORDS:                                                                  M
  308. *   CagdUVFreeList, free                                                     M
  309. *****************************************************************************/
  310. void CagdUVFreeList(CagdUVStruct *UVList)
  311. {
  312.     CagdUVStruct *UVTemp;
  313.  
  314.     while (UVList) {
  315.     UVTemp = UVList -> Pnext;
  316.     CagdUVFree(UVList);
  317.     UVList = UVTemp;
  318.     }
  319. }
  320.  
  321. /*****************************************************************************
  322. * DESCRIPTION:                                                               M
  323. * Deallocates and frees an array of UV structure.                 M
  324. *                                                                            *
  325. * PARAMETERS:                                                                M
  326. *   UVArray:     To be deallocated.                                          M
  327. *   Size:        Of the deallocated array.                                   M
  328. *                                                                            *
  329. * RETURN VALUE:                                                              M
  330. *   void                                                                     M
  331. *                                                                            *
  332. * KEYWORDS:                                                                  M
  333. *   CagdUVArrayFree, free                                                    M
  334. *****************************************************************************/
  335. void CagdUVArrayFree(CagdUVStruct *UVArray, int Size)
  336. {
  337.     int i;
  338.  
  339.     for (i = 0; i < Size; i++)
  340.     AttrFreeAttributes(&UVArray[i].Attr);
  341.  
  342.     IritFree((VoidPtr) UVArray);
  343. }
  344.  
  345. /*****************************************************************************
  346. * DESCRIPTION:                                                               M
  347. * Deallocates and frees all slots of a point structure.                     M
  348. *                                                                            *
  349. * PARAMETERS:                                                                M
  350. *   Pt:       To be deallocated.                                             M
  351. *                                                                            *
  352. * RETURN VALUE:                                                              M
  353. *   void                                                                     M
  354. *                                                                            *
  355. * KEYWORDS:                                                                  M
  356. *   CagdPtFree, free                                                         M
  357. *****************************************************************************/
  358. void CagdPtFree(CagdPtStruct *Pt)
  359. {
  360.     if (Pt == NULL)
  361.     return;
  362.  
  363.     AttrFreeAttributes(&Pt -> Attr);
  364.     IritFree((VoidPtr) Pt);
  365. }
  366.  
  367. /*****************************************************************************
  368. * DESCRIPTION:                                                               M
  369. * Deallocates and frees a point structure list:                     M
  370. *                                                                            *
  371. * PARAMETERS:                                                                M
  372. *   PtList:  To be deallocated.                                              M
  373. *                                                                            *
  374. * RETURN VALUE:                                                              M
  375. *   void                                                                     M
  376. *                                                                            *
  377. * KEYWORDS:                                                                  M
  378. *   CagdPtFreeList, free                                                     M
  379. *****************************************************************************/
  380. void CagdPtFreeList(CagdPtStruct *PtList)
  381. {
  382.     CagdPtStruct *PtTemp;
  383.  
  384.     while (PtList) {
  385.     PtTemp = PtList -> Pnext;
  386.     CagdPtFree(PtList);
  387.     PtList = PtTemp;
  388.     }
  389. }
  390.  
  391. /*****************************************************************************
  392. * DESCRIPTION:                                                               M
  393. * Deallocates and frees an array of Pt structure.                 M
  394. *                                                                            *
  395. * PARAMETERS:                                                                M
  396. *   PtArray:     To be deallocated.                                          M
  397. *   Size:        Of the deallocated array.                                   M
  398. *                                                                            *
  399. * RETURN VALUE:                                                              M
  400. *   void                                                                     M
  401. *                                                                            *
  402. * KEYWORDS:                                                                  M
  403. *   CagdPtArrayFree, free                                                    M
  404. *****************************************************************************/
  405. void CagdPtArrayFree(CagdPtStruct *PtArray, int Size)
  406. {
  407.     int i;
  408.  
  409.     for (i = 0; i < Size; i++)
  410.     AttrFreeAttributes(&PtArray[i].Attr);
  411.  
  412.     IritFree((VoidPtr) PtArray);
  413. }
  414.  
  415. /*****************************************************************************
  416. * DESCRIPTION:                                                               M
  417. * Deallocates and frees all slots of a CtlPt structure.                     M
  418. *                                                                            *
  419. * PARAMETERS:                                                                M
  420. *   CtlPt:       To be deallocated.                                          M
  421. *                                                                            *
  422. * RETURN VALUE:                                                              M
  423. *   void                                                                     M
  424. *                                                                            *
  425. * KEYWORDS:                                                                  M
  426. *   CagdCtlPtFree, free                                                      M
  427. *****************************************************************************/
  428. void CagdCtlPtFree(CagdCtlPtStruct *CtlPt)
  429. {
  430.     if (CtlPt == NULL)
  431.     return;
  432.  
  433.     AttrFreeAttributes(&CtlPt -> Attr);
  434.     IritFree((VoidPtr) CtlPt);
  435. }
  436.  
  437. /*****************************************************************************
  438. * DESCRIPTION:                                                               M
  439. * Deallocates and frees a CtlPt structure list:                     M
  440. *                                                                            *
  441. * PARAMETERS:                                                                M
  442. *   CtlPtList:  To be deallocated.                                           M
  443. *                                                                            *
  444. * RETURN VALUE:                                                              M
  445. *   void                                                                     M
  446. *                                                                            *
  447. * KEYWORDS:                                                                  M
  448. *   CagdCtlPtFreeList, free                                                  M
  449. *****************************************************************************/
  450. void CagdCtlPtFreeList(CagdCtlPtStruct *CtlPtList)
  451. {
  452.     CagdCtlPtStruct *CtlPtTemp;
  453.  
  454.     while (CtlPtList) {
  455.     CtlPtTemp = CtlPtList -> Pnext;
  456.     CagdCtlPtFree(CtlPtList);
  457.     CtlPtList = CtlPtTemp;
  458.     }
  459. }
  460.  
  461. /*****************************************************************************
  462. * DESCRIPTION:                                                               M
  463. * Deallocates and frees an array of CtlPt structure.                 M
  464. *                                                                            *
  465. * PARAMETERS:                                                                M
  466. *   CtlPtArray:     To be deallocated.                                       M
  467. *   Size:           Of the deallocated array.                                M
  468. *                                                                            *
  469. * RETURN VALUE:                                                              M
  470. *   void                                                                     M
  471. *                                                                            *
  472. * KEYWORDS:                                                                  M
  473. *   CagdCtlPtArrayFree, free                                                 M
  474. *****************************************************************************/
  475. void CagdCtlPtArrayFree(CagdCtlPtStruct *CtlPtArray, int Size)
  476. {
  477.     int i;
  478.  
  479.     for (i = 0; i < Size; i++)
  480.     AttrFreeAttributes(&CtlPtArray[i].Attr);
  481.  
  482.     IritFree((VoidPtr) CtlPtArray);
  483. }
  484.  
  485. /*****************************************************************************
  486. * DESCRIPTION:                                                               M
  487. * Deallocates and frees all slots of a vector structure.             M
  488. *                                                                            *
  489. * PARAMETERS:                                                                M
  490. *   Vec:       To be deallocated.                                            M
  491. *                                                                            *
  492. * RETURN VALUE:                                                              M
  493. *   void                                                                     M
  494. *                                                                            *
  495. * KEYWORDS:                                                                  M
  496. *   CagdVecFree, free                                                        M
  497. *****************************************************************************/
  498. void CagdVecFree(CagdVecStruct *Vec)
  499. {
  500.     if (Vec == NULL)
  501.     return;
  502.  
  503.     AttrFreeAttributes(&Vec -> Attr);
  504.     IritFree((VoidPtr) Vec);
  505. }
  506.  
  507. /*****************************************************************************
  508. * DESCRIPTION:                                                               M
  509. * Deallocates and frees a vector structure list:                 M
  510. *                                                                            *
  511. * PARAMETERS:                                                                M
  512. *   VecList:  To be deallocated.                                             M
  513. *                                                                            *
  514. * RETURN VALUE:                                                              M
  515. *   void                                                                     M
  516. *                                                                            *
  517. * KEYWORDS:                                                                  M
  518. *   CagdVecFreeList, free                                                    M
  519. *****************************************************************************/
  520. void CagdVecFreeList(CagdVecStruct *VecList)
  521. {
  522.     CagdVecStruct *VecTemp;
  523.  
  524.     while (VecList) {
  525.     VecTemp = VecList -> Pnext;
  526.     CagdVecFree(VecList);
  527.     VecList = VecTemp;
  528.     }
  529. }
  530.  
  531. /*****************************************************************************
  532. * DESCRIPTION:                                                               M
  533. * Deallocates and frees an array of vector structure.                 M
  534. *                                                                            *
  535. * PARAMETERS:                                                                M
  536. *   VecArray:     To be deallocated.                                         M
  537. *   Size:         Of the deallocated array.                                  M
  538. *                                                                            *
  539. * RETURN VALUE:                                                              M
  540. *   void                                                                     M
  541. *                                                                            *
  542. * KEYWORDS:                                                                  M
  543. *   CagdVecArrayFree, free                                                   M
  544. *****************************************************************************/
  545. void CagdVecArrayFree(CagdVecStruct *VecArray, int Size)
  546. {
  547.     int i;
  548.  
  549.     for (i = 0; i < Size; i++)
  550.     AttrFreeAttributes(&VecArray[i].Attr);
  551.  
  552.     IritFree((VoidPtr) VecArray);
  553. }
  554.  
  555. /*****************************************************************************
  556. * DESCRIPTION:                                                               M
  557. * Deallocates and frees all slots of a plane structure.                     M
  558. *                                                                            *
  559. * PARAMETERS:                                                                M
  560. *   Plane:       To be deallocated.                                          M
  561. *                                                                            *
  562. * RETURN VALUE:                                                              M
  563. *   void                                                                     M
  564. *                                                                            *
  565. * KEYWORDS:                                                                  M
  566. *   CagdPlaneFree, free                                                      M
  567. *****************************************************************************/
  568. void CagdPlaneFree(CagdPlaneStruct *Plane)
  569. {
  570.     if (Plane == NULL)
  571.     return;
  572.  
  573.     AttrFreeAttributes(&Plane -> Attr);
  574.     IritFree((VoidPtr) Plane);
  575. }
  576.  
  577. /*****************************************************************************
  578. * DESCRIPTION:                                                               M
  579. * Deallocates and frees a plane structure list:                     M
  580. *                                                                            *
  581. * PARAMETERS:                                                                M
  582. *   PlaneList:  To be deallocated.                                           M
  583. *                                                                            *
  584. * RETURN VALUE:                                                              M
  585. *   void                                                                     M
  586. *                                                                            *
  587. * KEYWORDS:                                                                  M
  588. *   CagdPlaneFreeList, free                                                  M
  589. *****************************************************************************/
  590. void CagdPlaneFreeList(CagdPlaneStruct *PlaneList)
  591. {
  592.     CagdPlaneStruct *PlaneTemp;
  593.  
  594.     while (PlaneList) {
  595.     PlaneTemp = PlaneList -> Pnext;
  596.     CagdPlaneFree(PlaneList);
  597.     PlaneList = PlaneTemp;
  598.     }
  599. }
  600.  
  601. /*****************************************************************************
  602. * DESCRIPTION:                                                               M
  603. * Deallocates and frees an array of plane structure.                 M
  604. *                                                                            *
  605. * PARAMETERS:                                                                M
  606. *   PlaneArray:     To be deallocated.                                       M
  607. *   Size:           Of the deallocated array.                                M
  608. *                                                                            *
  609. * RETURN VALUE:                                                              M
  610. *   void                                                                     M
  611. *                                                                            *
  612. * KEYWORDS:                                                                  M
  613. *   CagdPlaneArrayFree, free                                                 M
  614. *****************************************************************************/
  615. void CagdPlaneArrayFree(CagdPlaneStruct *PlaneArray, int Size)
  616. {
  617.     int i;
  618.  
  619.     for (i = 0; i < Size; i++)
  620.     AttrFreeAttributes(&PlaneArray[i].Attr);
  621.  
  622.     IritFree((VoidPtr) PlaneArray);
  623. }
  624.  
  625. /*****************************************************************************
  626. * DESCRIPTION:                                                               M
  627. * Deallocates and frees all slots of a BBox structure.                     M
  628. *                                                                            *
  629. * PARAMETERS:                                                                M
  630. *   BBox:       To be deallocated.                                           M
  631. *                                                                            *
  632. * RETURN VALUE:                                                              M
  633. *   void                                                                     M
  634. *                                                                            *
  635. * KEYWORDS:                                                                  M
  636. *   CagdBBoxFree, free                                                       M
  637. *****************************************************************************/
  638. void CagdBBoxFree(CagdBBoxStruct *BBox)
  639. {
  640.     if (BBox == NULL)
  641.     return;
  642.  
  643.     AttrFreeAttributes(&BBox -> Attr);
  644.     IritFree((VoidPtr) BBox);
  645. }
  646.  
  647. /*****************************************************************************
  648. * DESCRIPTION:                                                               M
  649. * Deallocates and frees a BBox structure list:                     M
  650. *                                                                            *
  651. * PARAMETERS:                                                                M
  652. *   BBoxList:  To be deallocated.                                            M
  653. *                                                                            *
  654. * RETURN VALUE:                                                              M
  655. *   void                                                                     M
  656. *                                                                            *
  657. * KEYWORDS:                                                                  M
  658. *   CagdBBoxFreeList, free                                                   M
  659. *****************************************************************************/
  660. void CagdBBoxFreeList(CagdBBoxStruct *BBoxList)
  661. {
  662.     CagdBBoxStruct *BBoxTemp;
  663.  
  664.     while (BBoxList) {
  665.     BBoxTemp = BBoxList -> Pnext;
  666.     CagdBBoxFree(BBoxList);
  667.     BBoxList = BBoxTemp;
  668.     }
  669. }
  670.  
  671. /*****************************************************************************
  672. * DESCRIPTION:                                                               M
  673. * Deallocates and frees an array of BBox structure.                 M
  674. *                                                                            *
  675. * PARAMETERS:                                                                M
  676. *   BBoxArray:    To be deallocated.                                         M
  677. *   Size:         Of the deallocated array.                                  M
  678. *                                                                            *
  679. * RETURN VALUE:                                                              M
  680. *   void                                                                     M
  681. *                                                                            *
  682. * KEYWORDS:                                                                  M
  683. *   CagdBBoxArrayFree, free                                                  M
  684. *****************************************************************************/
  685. void CagdBBoxArrayFree(CagdBBoxStruct *BBoxArray, int Size)
  686. {
  687.     int i;
  688.  
  689.     for (i = 0; i < Size; i++)
  690.     AttrFreeAttributes(&BBoxArray[i].Attr);
  691.  
  692.     IritFree((VoidPtr) BBoxArray);
  693. }
  694.  
  695. /*****************************************************************************
  696. * DESCRIPTION:                                                               M
  697. * Deallocates and frees all slots of a polyline structure.             M
  698. *                                                                            *
  699. * PARAMETERS:                                                                M
  700. *   Poly:       To be deallocated.                                           M
  701. *                                                                            *
  702. * RETURN VALUE:                                                              M
  703. *   void                                                                     M
  704. *                                                                            *
  705. * KEYWORDS:                                                                  M
  706. *   CagdPolylineFree, free                                                   M
  707. *****************************************************************************/
  708. void CagdPolylineFree(CagdPolylineStruct *Poly)
  709. {
  710.     if (Poly == NULL)
  711.     return;
  712.  
  713.     IritFree((VoidPtr) Poly -> Polyline);
  714.     AttrFreeAttributes(&Poly -> Attr);
  715.     IritFree((VoidPtr) Poly);
  716. }
  717.  
  718. /*****************************************************************************
  719. * DESCRIPTION:                                                               M
  720. * Deallocates and frees a polyline structure list:                 M
  721. *                                                                            *
  722. * PARAMETERS:                                                                M
  723. *   PolyList:  To be deallocated.                                            M
  724. *                                                                            *
  725. * RETURN VALUE:                                                              M
  726. *   void                                                                     M
  727. *                                                                            *
  728. * KEYWORDS:                                                                  M
  729. *   CagdPolylineFreeList, free                                               M
  730. *****************************************************************************/
  731. void CagdPolylineFreeList(CagdPolylineStruct *PolyList)
  732. {
  733.     CagdPolylineStruct *PolyTemp;
  734.  
  735.     while (PolyList) {
  736.     PolyTemp = PolyList -> Pnext;
  737.     CagdPolylineFree(PolyList);
  738.     PolyList = PolyTemp;
  739.     }
  740. }
  741.  
  742. /*****************************************************************************
  743. * DESCRIPTION:                                                               M
  744. * Deallocates and frees all slots of a polygon structure.                 M
  745. *                                                                            *
  746. * PARAMETERS:                                                                M
  747. *   Poly:       To be deallocated.                                           M
  748. *                                                                            *
  749. * RETURN VALUE:                                                              M
  750. *   void                                                                     M
  751. *                                                                            *
  752. * KEYWORDS:                                                                  M
  753. *   CagdPolygonFree, free                                                    M
  754. *****************************************************************************/
  755. void CagdPolygonFree(CagdPolygonStruct *Poly)
  756. {
  757.     if (Poly == NULL)
  758.     return;
  759.  
  760.     AttrFreeAttributes(&Poly -> Attr);
  761.     IritFree((VoidPtr) Poly);
  762. }
  763.  
  764. /*****************************************************************************
  765. * DESCRIPTION:                                                               M
  766. * Deallocates and frees a polygon structure list:                 M
  767. *                                                                            *
  768. * PARAMETERS:                                                                M
  769. *   PolyList:  To be deallocated.                                            M
  770. *                                                                            *
  771. * RETURN VALUE:                                                              M
  772. *   void                                                                     M
  773. *                                                                            *
  774. * KEYWORDS:                                                                  M
  775. *   CagdPolygonFreeList, free                                                M
  776. *****************************************************************************/
  777. void CagdPolygonFreeList(CagdPolygonStruct *PolyList)
  778. {
  779.     CagdPolygonStruct *PolyTemp;
  780.  
  781.     while (PolyList) {
  782.     PolyTemp = PolyList -> Pnext;
  783.     CagdPolygonFree(PolyList);
  784.     PolyList = PolyTemp;
  785.     }
  786. }
  787.  
  788. /*****************************************************************************
  789. * DESCRIPTION:                                                               M
  790. * Reverses a list of cagd library objects, in place.                         M
  791. *                                                                            *
  792. * PARAMETERS:                                                                M
  793. *   List:       To be reversed.                                              M
  794. *                                                                            *
  795. * RETURN VALUE:                                                              M
  796. *   VoidPtr:    Reversed list.                                               M
  797. *                                                                            *
  798. * KEYWORDS:                                                                  M
  799. *   CagdListReverse, reverse                                                 M
  800. *****************************************************************************/
  801. VoidPtr CagdListReverse(VoidPtr List)
  802. {
  803.     CagdGenericStruct
  804.     *OldHead = (CagdGenericStruct *) List,
  805.     *NewHead = NULL;
  806.  
  807.     while (OldHead) {
  808.     CagdGenericStruct
  809.         *TmpStruct = OldHead -> Pnext;
  810.  
  811.     OldHead -> Pnext = NewHead;
  812.     NewHead = OldHead;
  813.  
  814.     OldHead = TmpStruct;
  815.     }
  816.  
  817.     return (VoidPtr) NewHead;
  818. }
  819.  
  820. /*****************************************************************************
  821. * DESCRIPTION:                                                               M
  822. * Returns the last element of given list of cagd library objects.            M
  823. *                                                                            *
  824. * PARAMETERS:                                                                M
  825. *   List:       To return its last element,                                  M
  826. *                                                                            *
  827. * RETURN VALUE:                                                              M
  828. *   VoidPtr:    Last element.                                                M
  829. *                                                                            *
  830. * KEYWORDS:                                                                  M
  831. *   CagdListLast                                                     M
  832. *****************************************************************************/
  833. VoidPtr CagdListLast(VoidPtr List)
  834. {
  835.     CagdGenericStruct
  836.     *Head = (CagdGenericStruct *) List;
  837.  
  838.     if (Head == NULL)
  839.     return NULL;
  840.  
  841.     for ( ; Head -> Pnext != NULL; Head = Head -> Pnext);
  842.  
  843.     return (VoidPtr) Head;
  844. }
  845.  
  846. /*****************************************************************************
  847. * DESCRIPTION:                                                               M
  848. * Computes the length of a list.                                             M
  849. *                                                                            *
  850. * PARAMETERS:                                                                M
  851. *   List:          List of cagd objects.                                     M
  852. *                                                                            *
  853. * RETURN VALUE:                                                              M
  854. *   int:           Length of list.                                           M
  855. *                                                                            *
  856. * KEYWORDS:                                                                  M
  857. *   CagdListLength                                                           M
  858. *****************************************************************************/
  859. int CagdListLength(VoidPtr List)
  860. {
  861.     CagdGenericStruct
  862.     *Head = (CagdGenericStruct *) List;
  863.     int i;
  864.  
  865.     for (i = 0; Head != NULL; Head = Head -> Pnext, i++);
  866.  
  867.     return i;
  868. }
  869.  
  870. /*****************************************************************************
  871. * DESCRIPTION:                                                               M
  872. * Applies an affine transform, in place, to given curve Crv as specified by  M
  873. * Translate and Scale.                                 M
  874. *   Each control point is first translated by Translate and then scaled by   M
  875. * Scale.                                                             M
  876. *                                                                            *
  877. * PARAMETERS:                                                                M
  878. *   Crv:         To be affinely transformed.                                 M
  879. *   Translate:   Translation amount.                                         M
  880. *   Scale:       Scaling amount.                                             M
  881. *                                                                            *
  882. * RETURN VALUE:                                                              M
  883. *   void                                                                     M
  884. *                                                                            *
  885. * KEYWORDS:                                                                  M
  886. *   CagdCrvTransform, scaling, translation, transformations                  M
  887. *****************************************************************************/
  888. void CagdCrvTransform(CagdCrvStruct *Crv,
  889.               CagdRType *Translate,
  890.               CagdRType Scale)
  891. {
  892.     switch (Crv -> GType) {
  893.     case CAGD_CBEZIER_TYPE:
  894.     case CAGD_CBSPLINE_TYPE:
  895.             CagdTransform(Crv -> Points,
  896.               Crv -> Length,
  897.                   CAGD_NUM_OF_PT_COORD(Crv -> PType),
  898.                   !CAGD_IS_RATIONAL_CRV(Crv),
  899.               Translate,
  900.               Scale);
  901.  
  902.         break;
  903.     case CAGD_CPOWER_TYPE:
  904.         CAGD_FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  905.         break;
  906.     default:
  907.         CAGD_FATAL_ERROR(CAGD_ERR_UNDEF_CRV);
  908.         break;
  909.     }
  910. }
  911.  
  912. /*****************************************************************************
  913. * DESCRIPTION:                                                               M
  914. * Applies an affine transform, in place, to given surface Srf as specified   M
  915. * by Translate and Scale.                             M
  916. *   Each control point is first translated by Translate and then scaled by   M
  917. * Scale.                                                             M
  918. *                                                                            *
  919. * PARAMETERS:                                                                M
  920. *   Crv:         To be affinely transformed.                                 M
  921. *   Translate:   Translation amount.                                         M
  922. *   Scale:       Scaling amount.                                             M
  923. *                                                                            *
  924. * RETURN VALUE:                                                              M
  925. *   void                                                                     M
  926. *                                                                            *
  927. * KEYWORDS:                                                                  M
  928. *   CagdSrfTransform, scaling, translation, transformations                  M
  929. *****************************************************************************/
  930. void CagdSrfTransform(CagdSrfStruct *Srf,
  931.               CagdRType *Translate,
  932.               CagdRType Scale)
  933. {
  934.     switch (Srf -> GType) {
  935.     case CAGD_SBEZIER_TYPE:
  936.     case CAGD_SBSPLINE_TYPE:
  937.         CagdTransform(Srf -> Points,
  938.                   Srf -> ULength * Srf -> VLength,
  939.                       CAGD_NUM_OF_PT_COORD(Srf -> PType),
  940.               !CAGD_IS_RATIONAL_SRF(Srf),
  941.                   Translate,
  942.                       Scale);
  943.         break;
  944.     case CAGD_SPOWER_TYPE:
  945.         CAGD_FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  946.         break;
  947.     default:
  948.         CAGD_FATAL_ERROR(CAGD_ERR_UNDEF_SRF);
  949.         break;
  950.     }
  951. }
  952.  
  953. /*****************************************************************************
  954. * DESCRIPTION:                                                               M
  955. * Applies an affine transform, in place, to given set of points Points which M
  956. * as array of vectors, each vector of length Len.                            M
  957. *   Array Points optionally contains (if !IsNotRational) in Points[0] the    M
  958. * weights coefficients and in Points[i] the coefficients of axis i, up to    M
  959. * and include MaxCoord (X = 1, Y = 2, etc.).                     M
  960. * Points are translated and scaled as prescribed by Translate and Scale.     M
  961. *   Each control point is first translated by Translate and then scaled by   M
  962. * Scale.                                                             M
  963. *                                                                            *
  964. * PARAMETERS:                                                                M
  965. *   Points:         To be affinely transformed. Array of vectors.            M
  966. *   Len:            Of vectors of Points.                                    M
  967. *   MaxCoord:       Maximum number of coordinates to be found in Points.     M
  968. *   IsNotRational:  Do we have weights as vector Points[0]?                  M
  969. *   Translate:      Translation amount.                                      M
  970. *   Scale:          Scaling amount.                                          M
  971. *                                                                            *
  972. * RETURN VALUE:                                                              M
  973. *   void                                                                     M
  974. *                                                                            *
  975. * KEYWORDS:                                                                  M
  976. *   CagdTransform, scaling, translation, transformations                     M
  977. *****************************************************************************/
  978. void CagdTransform(CagdRType **Points,
  979.            int Len,
  980.            int MaxCoord,
  981.            CagdBType IsNotRational,
  982.            CagdRType *Translate,
  983.            CagdRType Scale)
  984. {
  985.     int i, j;
  986.  
  987.     if (IsNotRational)
  988.     for (i = 1; i <= MaxCoord; i++)
  989.         for (j = 0; j < Len; j++)
  990.         Points[i][j] = (Points[i][j] + Translate[i - 1]) * Scale;
  991.     else
  992.     for (i = 1; i <= MaxCoord; i++)
  993.         for (j = 0; j < Len; j++)
  994.         Points[i][j] = (Points[i][j] +
  995.                 Translate[i - 1] * Points[W][j]) * Scale;
  996. }
  997.  
  998. /*****************************************************************************
  999. * DESCRIPTION:                                                               M
  1000. * Applies an homogeneous transformation, in place, to the given curve Crv as M
  1001. * specified by homogeneous transformation Mat.                     M
  1002. *                                                                            *
  1003. * PARAMETERS:                                                                M
  1004. *   Crv:       To be transformed.                                            M
  1005. *   Mat:       Defining the transformation.                                  M
  1006. *                                                                            *
  1007. * RETURN VALUE:                                                              M
  1008. *   void                                                                     M
  1009. *                                                                            *
  1010. * KEYWORDS:                                                                  M
  1011. *   CagdCrvMatTransform, scaling, rotation, translation, transformations     M
  1012. *****************************************************************************/
  1013. void CagdCrvMatTransform(CagdCrvStruct *Crv, CagdMType Mat)
  1014. {
  1015.     switch (Crv -> GType) {
  1016.     case CAGD_CBEZIER_TYPE:
  1017.     case CAGD_CBSPLINE_TYPE:
  1018.         switch (Crv -> PType) {               /* Make sure input is 3D. */
  1019.         case CAGD_PT_E2_TYPE:
  1020.         case CAGD_PT_P2_TYPE:
  1021.             {
  1022.             int i,
  1023.                 Len = Crv -> Length;
  1024.  
  1025.             Crv -> Points[3] =
  1026.                 (CagdRType *) IritMalloc(sizeof(CagdRType) * Len);
  1027.  
  1028.             for (i = 0; i < Len; i++)
  1029.                 Crv -> Points[3][i] = 0.0;
  1030.             Crv -> PType = (Crv -> PType == CAGD_PT_E2_TYPE ?
  1031.                     CAGD_PT_E3_TYPE : CAGD_PT_P3_TYPE);
  1032.             break;
  1033.             }
  1034.         case CAGD_PT_E3_TYPE:
  1035.         case CAGD_PT_P3_TYPE:
  1036.             break;
  1037.         default:
  1038.             CAGD_FATAL_ERROR(CAGD_ERR_ONLY_2D_OR_3D);
  1039.             return;
  1040.         }
  1041.  
  1042.         CagdMatTransform(Crv -> Points,
  1043.                      Crv -> Length,
  1044.                          CAGD_NUM_OF_PT_COORD(Crv -> PType),
  1045.                  !CAGD_IS_RATIONAL_CRV(Crv),
  1046.                      Mat);
  1047.         break;
  1048.     case CAGD_CPOWER_TYPE:
  1049.         CAGD_FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  1050.         break;
  1051.     default:
  1052.         CAGD_FATAL_ERROR(CAGD_ERR_UNDEF_CRV);
  1053.         break;
  1054.     }
  1055. }
  1056.  
  1057. /*****************************************************************************
  1058. * DESCRIPTION:                                                               M
  1059. * Applies an homogeneous transformation, in place, to the given surface Srf  M
  1060. * as specified by homogeneous transformation Mat.                 M
  1061. *                                                                            *
  1062. * PARAMETERS:                                                                M
  1063. *   Srf:       To be transformed.                                            M
  1064. *   Mat:       Defining the transformation.                                  M
  1065. *                                                                            *
  1066. * RETURN VALUE:                                                              M
  1067. *   void                                                                     M
  1068. *                                                                            *
  1069. * KEYWORDS:                                                                  M
  1070. *   CagdSrfMatTransform, scaling, rotation, translation, transformations     M
  1071. *****************************************************************************/
  1072. void CagdSrfMatTransform(CagdSrfStruct *Srf, CagdMType Mat)
  1073. {
  1074.     switch (Srf -> GType) {
  1075.     case CAGD_SBEZIER_TYPE:
  1076.     case CAGD_SBSPLINE_TYPE:
  1077.         switch (Srf -> PType) {               /* Make sure input is 3D. */
  1078.         case CAGD_PT_E2_TYPE:
  1079.         case CAGD_PT_P2_TYPE:
  1080.             {
  1081.             int i,
  1082.             Len = Srf -> ULength * Srf ->VLength;
  1083.  
  1084.             Srf -> Points[3] =
  1085.                 (CagdRType *) IritMalloc(sizeof(CagdRType) * Len);
  1086.  
  1087.             for (i = 0; i < Len; i++)
  1088.                 Srf -> Points[3][i] = 0.0;
  1089.             Srf -> PType = (Srf -> PType == CAGD_PT_E2_TYPE ?
  1090.                     CAGD_PT_E3_TYPE : CAGD_PT_P3_TYPE);
  1091.             break;
  1092.             }
  1093.         case CAGD_PT_E3_TYPE:
  1094.         case CAGD_PT_P3_TYPE:
  1095.             break;
  1096.         default:
  1097.             CAGD_FATAL_ERROR(CAGD_ERR_ONLY_2D_OR_3D);
  1098.             return;
  1099.         }
  1100.         CagdMatTransform(Srf -> Points,
  1101.                      Srf -> ULength * Srf -> VLength,
  1102.                          CAGD_NUM_OF_PT_COORD(Srf -> PType),
  1103.                  !CAGD_IS_RATIONAL_SRF(Srf),
  1104.                      Mat);
  1105.         break;
  1106.     case CAGD_SPOWER_TYPE:
  1107.         CAGD_FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  1108.         break;
  1109.     default:
  1110.         CAGD_FATAL_ERROR(CAGD_ERR_UNDEF_SRF);
  1111.         break;
  1112.     }
  1113. }
  1114.  
  1115. /*****************************************************************************
  1116. * DESCRIPTION:                                                               M
  1117. * Applies an homogeneous transformation, in place, to given set of points    M
  1118. * Points which as array of vectors, each vector of length Len.               M
  1119. *   Array Points optionally contains (if !IsNotRational) in Points[0] the    M
  1120. * weights coefficients and in Points[i] the coefficients of axis i, up to    M
  1121. * and include MaxCoord (X = 1, Y = 2, etc.).                     M
  1122. *                                                                            *
  1123. * PARAMETERS:                                                                M
  1124. *   Points:         To be affinely transformed. Array of vectors.            M
  1125. *   Len:            Of vectors of Points.                                    M
  1126. *   MaxCoord:       Maximum number of coordinates to be found in Points.     M
  1127. *   IsNotRational:  Do we have weights as vector Points[0]?                  M
  1128. *   Mat:       Defining the transformation.                                  M
  1129. *                                                                            *
  1130. * RETURN VALUE:                                                              M
  1131. *   void                                                                     M
  1132. *                                                                            *
  1133. * KEYWORDS:                                                                  M
  1134. *   CagdMatTransform, scaling, rotation, translation, transformations        M
  1135. *****************************************************************************/
  1136. void CagdMatTransform(CagdRType **Points,
  1137.               int Len,
  1138.               int MaxCoord,
  1139.               CagdBType IsNotRational,
  1140.               CagdMType Mat)
  1141. {
  1142.     int i, j;
  1143.     CagdRType P[4], Q[4];
  1144.  
  1145.     if (MaxCoord > 3)
  1146.     MaxCoord = 3;
  1147.  
  1148.     if (IsNotRational)
  1149.     for (i = 0; i < Len; i++) {
  1150.         for (j = 1; j <= MaxCoord; j++)
  1151.         P[j - 1] = Points[j][i];
  1152.  
  1153.         /* Zero unused coords. */
  1154.         for (j = MaxCoord + 1; j < 3; i++)
  1155.         P[j - 1] = 0.0;
  1156.  
  1157.             MatMultVecby4by4(Q, P, Mat);
  1158.  
  1159.         for (j = 1; j <= MaxCoord; j++)
  1160.         Points[j][i] = Q[j - 1];
  1161.         }
  1162.     else
  1163.     for (i = 0; i < Len; i++) {
  1164.         for (j = 1; j <= MaxCoord; j++)
  1165.         P[j - 1] = Points[j][i];
  1166.         P[3] = Points[W][i];
  1167.  
  1168.         /* Zero unused coords. */
  1169.         for (j = MaxCoord + 1; j < 3; i++)
  1170.         P[j - 1] = 0.0;
  1171.  
  1172.             MatMultWVecby4by4(Q, P, Mat);
  1173.  
  1174.         for (j = 1; j <= MaxCoord; j++)
  1175.         Points[j][i] = Q[j - 1];
  1176.         Points[W][i] = Q[3];
  1177.         }
  1178. }
  1179.  
  1180. /*****************************************************************************
  1181. * DESCRIPTION:                                                               *
  1182. * Routine to create one triangular polygon, given its vertices.             *
  1183. * Returns NULL if Triangle is degenerated.                     *
  1184. *                                                                            *
  1185. * PARAMETERS:                                                                *
  1186. *   ComputeNormals:   If TRUE then use Nl? parameters. Nl? are valid.        *
  1187. *   ComputeUV:        If TRUE then use UV? parameters. UV? are valid.        *
  1188. *   Pt1, Pt2, Pt3:    Euclidean locations of vertices.                       *
  1189. *   Nl1, Nl2, Nl3:    Optional Normals of vertices (if ComputeNormals).      *
  1190. *   UV1, UV2, UV3:    Optional UV parametric location of vertices (if        *
  1191. *                     ComputeUV).                                            *
  1192. *                                                                            *
  1193. * RETURN VALUE:                                                              *
  1194. *   CagdPolygonStruct *:  A polygonal triangle structure, or NULL if points  *
  1195. *                         are colinear.                                      *
  1196. *                                                                            *
  1197. * KEYWORDS:                                                                  *
  1198. *   _CagdMakePolygon                                                         *
  1199. *****************************************************************************/
  1200. CagdPolygonStruct *_CagdMakePolygon(CagdBType ComputeNormals,
  1201.                     CagdBType ComputeUV,
  1202.                     CagdPtStruct *Pt1,
  1203.                     CagdPtStruct *Pt2,
  1204.                     CagdPtStruct *Pt3,
  1205.                     CagdVecStruct *Nl1,
  1206.                     CagdVecStruct *Nl2,
  1207.                     CagdVecStruct *Nl3,
  1208.                     CagdUVStruct *UV1,
  1209.                     CagdUVStruct *UV2,
  1210.                     CagdUVStruct *UV3)
  1211. {
  1212.     CagdPolygonStruct *Poly;
  1213.  
  1214.     if (GMColinear3Pts(Pt1 -> Pt, Pt2 -> Pt, Pt3 -> Pt))
  1215.     return NULL;
  1216.  
  1217.     Poly = CagdPolygonNew();
  1218.  
  1219.     PT_COPY(Poly -> Polygon[0].Pt, Pt1 -> Pt);
  1220.     PT_COPY(Poly -> Polygon[1].Pt, Pt2 -> Pt);
  1221.     PT_COPY(Poly -> Polygon[2].Pt, Pt3 -> Pt);
  1222.  
  1223.     if (ComputeNormals) {
  1224.     PT_COPY(Poly -> Polygon[0].Nrml, Nl1 -> Vec);
  1225.     PT_COPY(Poly -> Polygon[1].Nrml, Nl2 -> Vec);
  1226.     PT_COPY(Poly -> Polygon[2].Nrml, Nl3 -> Vec);
  1227.     }
  1228.     else {
  1229.     PT_RESET(Poly -> Polygon[0].Nrml);
  1230.     PT_RESET(Poly -> Polygon[1].Nrml);
  1231.     PT_RESET(Poly -> Polygon[2].Nrml);
  1232.     }
  1233.  
  1234.     if (ComputeUV) {
  1235.     UV_COPY(Poly -> Polygon[0].UV, UV1 -> UV);
  1236.     UV_COPY(Poly -> Polygon[1].UV, UV2 -> UV);
  1237.     UV_COPY(Poly -> Polygon[2].UV, UV3 -> UV);
  1238.     }
  1239.     else {
  1240.     UV_RESET(Poly -> Polygon[0].UV);
  1241.     UV_RESET(Poly -> Polygon[1].UV);
  1242.     UV_RESET(Poly -> Polygon[2].UV);
  1243.     }
  1244.  
  1245.     return Poly;
  1246. }
  1247.  
  1248. /*****************************************************************************
  1249. * DESCRIPTION:                                                               M
  1250. * Sets the way (co)linear surfaces are converted into polygons.             M
  1251. *                                                                            *
  1252. * PARAMETERS:                                                                M
  1253. *   Lin2Poly:  Specification.                                                M
  1254. *                                                                            *
  1255. * RETURN VALUE:                                                              M
  1256. *   void                                                                     M
  1257. *                                                                            *
  1258. * KEYWORDS:                                                                  M
  1259. *   CagdSetLinear2Poly, polygonization, polygonal approximation              M
  1260. *****************************************************************************/
  1261. void CagdSetLinear2Poly(CagdLin2PolyType Lin2Poly)
  1262. {
  1263.     _CagdLin2Poly = Lin2Poly;
  1264. }
  1265.